package com.xxcxcxcx.xc_crop.mixin;

import com.xxcxcxcx.xc_crop.common.Configuration;
import com.xxcxcxcx.xc_crop.common.ReadConfig;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.CropBlock;
import net.minecraft.world.level.block.NetherWartBlock;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.ArrayList;

@Mixin(NetherWartBlock.class)
public abstract class NetherWartBlockMixin extends BlockBehaviour implements ReadConfig {
    public NetherWartBlockMixin(Properties p_60452_) {
        super(p_60452_);
    }
    private String ConfigKey = "NetherWart";
    private ArrayList<String> biomeWhiteList = new ArrayList<>();
    private boolean whitelistRead = false;//保证config只读一次
    public boolean canBiome(BlockPos pos, LevelReader levelReader){
        Biome.BiomeCategory currentBiome = Biome.getBiomeCategory(levelReader.getBiome(pos));
        if(!whitelistRead)ReadConfigMessage();
        return biomeWhiteList.isEmpty()||biomeWhiteList.contains(currentBiome.getName());
    }
    public void ReadConfigMessage(){
        biomeWhiteList = Configuration.whitelistStrtoArraylist(Configuration.Config.get(ConfigKey));
        whitelistRead = true;
    }
    @Override
    public boolean canSurvive(BlockState p_52282_, LevelReader p_52283_, BlockPos p_52284_) {
        return super.canSurvive(p_52282_,p_52283_,p_52284_)&&p_52283_.canSeeSky(p_52284_)&&canBiome(p_52284_,p_52283_);
    }
}